<%layout("/common/_layout.html"){ %>
  <%#ajax userTable:{%>
  <div class="am-cf am-padding">
    <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">业务管理</strong> / <small>宽带套餐管理</small></div>
  </div>
  <div class="am-g">
    <%include("broadband_query.tpl"){}%>
    <div class="am-u-sm-12 am-u-md-12" style="padding:0 1.6rem 1.6rem 1rem;margin:0;">
      <div class="am-btn-toolbar" style="padding-left:.5rem;">
        <div class="am-btn-group am-btn-group-xs">
          <%if(so.hasPermission("BROADBAND_ADD")) {%>
          <button type="button" class="am-btn am-btn-default" onclick="location.href='${base}/broadband/add'"><span class="am-icon-plus"></span> 新增</button>
          <%}%>
          <%if(so.hasPermission("BROADBAND_DELETE")) {%>
          <button type="button" id="deleteButton" disabled="disabled" class="am-btn am-btn-default"  onclick="deleteAll('${base}/broadband/delete')"><span class="am-icon-trash-o"></span> 删除</button>
          <%}%>
          <%if(so.hasPermission("BROADBAND_ENABLE")) {%>
            <button type="button" id="enableButton" class="am-btn am-btn-default" onclick="enableAll('${base}/broadband/enable')" disabled>
                <span class="am-icon-toggle-on"></span>
                启用
            </button>
          <%}%>
          <%if(so.hasPermission("BROADBAND_DISABLE")) {%>
            <button type="button" id="disableButton" class="am-btn am-btn-default" onclick="disableAll('${base}/broadband/disable')" disabled>
                <span class="am-icon-toggle-off"></span>
                禁用
            </button>
          <%}%>
        </div>
      </div>
    </div>
  </div>
  <div class="am-g">
    <div class="am-u-sm-12">
      <div class="am-scrollable-horizontal">
        <table class="am-table am-table-striped am-table-hover table-main">
          <thead>
            <tr class="am-text-nowrap">
              <th class="table-check"><input type="checkbox"  id="allCheck"/></th>
              <th class="table-title">业务名称</th>
              <th class="table-title">宽带类型</th>
              <th class="table-title">业务简介</th>
              <th class="table-title">宽带价格</th>
              <th class="table-title">宽带带宽</th>
              <th class="table-title">宽带品牌</th>
              <th class="table-title">所属城市</th>
              <th class="table-title">计费周期</th>
              <th class="table-title">适用范围</th>
              <th class="table-title">发布人</th>
              <th class="table-title">发布人机构名称</th>
              <th class="table-title">资费代码</th>
              <th class="table-title">排序</th>
              <th class="table-title">是否启用</th>
              <th class="table-set">操作</th>
            </tr>
          </thead>
          <tbody>
            <%for(list in pager.list!){%>
              <tr>
                <td><input type="checkbox" name="ids" value="${list.id}"></td>
                <td>
                <%if(so.hasPermission("BROADBAND_EDIT")) {%>
                  <a href="${base}/broadband/edit?broadband.id=${list.id}">${list.name}</a>
                <%}else{%>
                  ${list.name}
                <%}%>
                </td>
                <td>
                 <%if(list.broad_type == 0) {%>
                                                                 爱家小区
                 <%}%>
                 <%else if(list.broad_type ==1) {%>
                                                                 优家小区
                 <%}%>
                 <%else if(list.broad_type == 2) {%>
                                                                商务动力
                 <%}%>
                 <%else if(list.broad_type == 3) {%>
                                                               校园套餐
                 <%}%>
                </td>
                <td>${list.business_summary}</td>
                <td>${list.price}</td>
                <td>${list.width}</td>
                <td>${list.brand}</td>
                <td>${list.city}</td>
                <td>${list.period}</td>
                <td>
                 <%if(list.business_type == 1) {%>
                                                                  开户
                 <%}%>
                 <%else if(list.business_type ==2) {%>
                                                                 预约
                 <%}%>
                 <%else if(list.business_type == 3) {%>
                                                                开户、预约
                 <%}%>
                </td>
                <td>${list.user_name}</td>
                <td>${list.org_name}</td>
                <td>${list.business_code}</td>
                <td>${list.order_num}</td>
                <td id='broadband_enabled'><%if(list.enabled==1) {%>
                  是                                                                  
                 <%}%>
                 <%else{%>
                  否
                 <%}%></td>
                <td id='operated'>
                  <div id ="edit-div" class="am-btn-toolbar <%if(list.enabled == 1) {%>am-hide<%}%>">
                    <div class="am-btn-group am-btn-group-xs">    
                      <%if(so.hasPermission("BROADBAND_EDIT")) {%>                
                      <button type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="location.href='${base}/broadband/edit?broadband.id=${list.id}'"><span class="am-icon-pencil-square-o"></span>修改</button>
                      <%}%>
                    </div>
                  </div>
                </td>         
              </tr>
             <%}%> 
          </tbody>
       </table>
     </div>
      <div class="am-cf">
         <!-- 分页 -->
         <%if (pager.list.~size > 0){%>
             <div class="am-fr">
                 <% include("/admin/common_pager.tpl"){}%>
             </div>
         <%}else{%>
             <div class="am-kai">
               <h3>没有找到任何记录!</h3>
             </div>
         <%}%>
      </div>
    </div>
  </div>
  <script type="text/javascript">
    var urlBase = "${base}";
    var url;
    $(document).ready(function() {
      var $allCheck = $("#allCheck");// 全选复选框
      var $idsCheck = $('[name=ids]:checkbox');// ID复选框
      var $enableButton = $("#enableButton");// 删除按钮
      var $disableButton = $("#disableButton");// 查询按钮
      $allCheck.checkAll();
      // 全选
      $allCheck.click(function() {
          $allCheck.checkAll();
          var isChecked = $allCheck.is(":checked");
          if (isChecked == false) {
              $enableButton.prop("disabled", true);
              $disableButton.prop("disabled", true);
          } else {
              $enableButton.prop("disabled", false);
              $disableButton.prop("disabled", false);
          }
      });

      // 无复选框被选中时,删除按钮不可用
      $idsCheck.click(function() {
          var $idsChecked = $("[name='ids']:checked");
          if ($idsChecked.size() > 0) {
              $enableButton.prop("disabled", false);
              $disableButton.prop("disabled", false);
          } else {
              $enableButton.prop("disabled", true);
              $disableButton.prop("disabled", true);
          }
      });   
    });   

    function enableAll(url){
      batchProcess($("#enableButton"), url, '启用','是');
    }

    function disableAll(url){
      batchProcess($("#disableButton"), url, '禁用','否');
    }  

    function batchProcess(btnObj, url, actinoName, value) {
      var $idsCheckedCheck = $("[name='ids']:checked");
      var $deleteButton = btnObj;// 删除按钮
      var ids = $idsCheckedCheck.serialize();
      if (confirm('您确定要'+actinoName+'吗？') == true) {       
          $.ajax({
            url : url,
            data : ids,
            dataType : "json",
            async : false,
            beforeSend : function(data) {
                $deleteButton.prop("disabled", true)
            },
            success : function(data) {
              $deleteButton.prop("disabled", false)
              if (data.status == "success") {
                $idsCheckedCheck.parent().parent().find('#broadband_enabled').html(value);
                if(actinoName == '禁用'){                        
                  $idsCheckedCheck.parent().parent().find('#operated').find('#edit-div').removeClass('am-hide');                       
                }else if(actinoName =='启用'){
                  $idsCheckedCheck.parent().parent().find('#operated').find('#edit-div').addClass('am-hide');
                }
              }
              sendMessage({
                title : actinoName,
                text : data.message,
                type : "success",
                timer : 2000,
                showConfirmButton : false
              });                
            }
          });
        }
      }
    </script>
  <%}%>
<%}%>



